/*  This file is part of -_-.

    -_- is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    -_- is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with -_-.  If not, see <http://www.gnu.org/licenses/>.

    Copyright 2012 Oliver Katz */

#include "../../../visual/display_engine/display_engine_api.h"

using namespace sleepyface;
using namespace sleepyface::visual;
using namespace sleepyface::visual::layout_engine;
using namespace sleepyface::visual::display_engine;

Z_WIDGET_SIZE(text, w, h)
{
    return h;
}

Z_WIDGET_RENDER(text, w, x, y, s)
{
    Backend vb = Z_GET_VISUAL_BACKEND();
    vb.loadFont(w->getString("font"));
    vb.text(x, y, w->getInt("r"), w->getInt("g"), w->getInt("b"), w->getInt("a"), w->getString("font"), w->getString("value"));
    return new DisplayBox();
}

Z_CONTAINER_SIZE(box, c, h)
{
    return z_box_minimum(h, 20, 20);
}

Z_CONTAINER_HINT(box, c, s)
{
    vector<pair<DisplayBox, DisplayBox> > rtn;
    pair<DisplayBox, DisplayBox> tmp;
    tmp.first = *s;
    tmp.second = DisplayBox(10, 10);
    rtn.push_back(tmp);
    Z_RETURN_HINTS(rtn);
}

Z_CONTAINER_RENDER(box, c, x, y, s)
{
    Backend vb = Z_GET_VISUAL_BACKEND();
    vb.rect(x, y, x+s->getWidth(), y+s->getHeight(), 0x33, 0x33, 0x33, 0xff);
    vb.rect(x+5, y+5, x+s->getWidth()-10, y+s->getHeight()-10, 0x22, 0x22, 0x22, 0xff);
    return new DisplayBox();
}

Z_BEGIN_LINKAGE()

Z_LINK_WIDGET(text)
Z_LINK_CONTAINER(box)

Z_BEGIN_LINKAGE_WIDGET_LIST()
Z_LIST(text)
Z_END_LINKAGE_WIDGET_LIST()

Z_BEGIN_LINKAGE_CONTAINER_LIST()
Z_LIST(box)
Z_END_LINKAGE_CONTAINER_LIST()

Z_END_LINKAGE()
